 <?php 
header('content-type: application/json; charset=utf-8');
header("access-control-allow-origin: *");
	require 'include/mysql_connect.php';
	require 'include/Functions.php';
	
	$server = true;
	//set_time_limit(300);
	
	if( $server){
		$function = $_GET['function'];
		$user_name = isset($_GET['user_name']) ? $_GET['user_name'] : '';	
	}
	else{
		$data = file_get_contents("php://input");
		$data = utf8_encode($data);
		
		
		$obj = json_decode($data, true);
		
		var_dump($obj);
		
		$function= $obj[0]['function'];	
		$user_name = $obj[0]['user_name'];
	}

	//var_dump(json_decode($data, true));
	
	function getSingleRow($user_name)
	{
		$user_name = addslashes($user_name);
		$sql= "SELECT * FROM person WHERE user_name = '".$user_name."'";
		//echo $sql;
		$result = Functions::getArraySql($sql);

	   if(count($result) != 0)
		{
			$array = array(
				'id' => $result['id'], 
				'pass' => $result['user_pass']
			);
			// An array is not needed for a single value.
			return $array;
		}
		return false;				
	}			
	

	if($function == 'getUserByUsername')
	{
	   // Assume that the previously defined query exists.
		$results = getSingleRow($user_name);
		if($results !== false)
		{
			 $json[] = array
			 (
				 'user_id' => $results['id'],
				 'user_pass' => $results['pass'],
				 'message' => 'success'
			 );
		}
		else // Nothing found in database
		{ 
			$json[] = array
			(
				 'message' => 'nothing found'
			);
		}
	}
	else
	{
		$json[] = array
		(
			'message' => 'Not Requested'
		);
	}
	//echo json_encode($json);
	echo 'localJsonpCallback('.json_encode($json).');';	
	flush();			
?>